package zdream.pmfield.data.foe;

import java.util.Arrays;
import java.util.Objects;

import zdream.utils.StringUtils;

/**
 * @author Zdream
 * @date 2023-11-30
 * @since 0.0.1
 */
public class MoveTarget {
	public final MoveTargetType type;
	/**
	 * 请确保生成时, range 是有序的, 而且从小到大排列
	 */
	public final int[] range;
	public final MoveRouteType route;
	public final MoveBlastType blast;

	public MoveTarget(MoveTargetType type, int... range) {
		this.type = Objects.requireNonNull(type);
		this.range = Objects.requireNonNull(range);
		this.route = MoveRouteType.DIRECT;
		this.blast = MoveBlastType.SINGLE;
	}

	public MoveTarget(MoveTargetType type, MoveRouteType route, MoveBlastType blast, int... range) {
		this.type = Objects.requireNonNull(type);
		this.range = Objects.requireNonNull(range);
		this.route = Objects.requireNonNull(route);
		this.blast = Objects.requireNonNull(blast);
	}

	public boolean isValidDistance(int distance) {
		final int index = Arrays.binarySearch(range, distance);
		return index >= 0;
	}

	@Override
	public String toString() {
		return String.format("%s:%s:%s:%s",
				type.name().toLowerCase(),
				StringUtils.join(",", range),
				route.name().toLowerCase(),
				blast.info);
	}
}
